package cn.hinglo.website.config.event;

import cn.hinglo.baseservice.event.UserApplicationEvent;
import cn.hinglo.common.entity.EventDto;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;


/**
 * @createTime: 2018/10/18 9:59
 * @author: HingLo
 * @description: 事件监听机制测试
 */
@Component
@EnableAsync
public class UserEventListener {

    /**
     * 事件监听方法
     *
     * @param event 传入事件类型
     */
    @EventListener(value = UserApplicationEvent.class, condition = "#root.event!=null")
    @Async
    public void listenServiceEvent(UserApplicationEvent event) {
        EventDto eventDto = (EventDto) event.getSource();
        Object o = eventDto.getSource();
        Integer type = eventDto.getType();
        // **************事件处理在此处进行具体实现*********************
        System.out.println("Test1Event：获取到事件机制");
        System.out.println("Test1Event：时间类型" + type);
        System.out.println("Test1Event：传输的内容" + o);
    }

}
